/**
 * 工具脚本, 用于批量把现有的各大纲范围数据更新到mongodb中
 * */
var fs = require('fs');
var mongoConn = require('./store').mongoConn;

var scaleConfig = [
  '../data/category/xiaoxue.txt',
  '../data/category/chuzhong.txt',
  '../data/category/gaozhong.txt'
];

var dict = {};

for (var i = scaleConfig.length - 1; i >= 0; i--) {
  var path = scaleConfig[i];
  var currentDict = fs.readFileSync(path).toString().split(/\s+/);
  for (var j = 0; j < currentDict.length; j++) {
    if (currentDict[j].trim().length > 0)
      dict[currentDict[j]] = i+1;
  }
}

var arr = {
  1: [],
  2: [],
  3: []
};

for(var word in dict) {
  arr[dict[word]].push(word);
}

mongoConn.update('words', { word: {$in : arr[1]}}, { scale: 1},function () {
  mongoConn.update('words', { word: {$in : arr[2]}}, { scale: 2},function () {
    mongoConn.update('words', { word: {$in : arr[3]}}, { scale: 3},function () {
      console.log('done');
    });
  });
});